<?php
session_start();
require_once("dbs.php");
require_once("classes/clss_imp.php");

	// checkSession() function start
function checkSession()
{
	$result = false;
	if(!empty($_SESSION['user']))
	{
		$result = true;
	}
	return $result; 
}// end of checkSession() function

	// errorMSG() function start
function errorMSG()
{	
	echo "<meta http-equiv='refresh' content='=2;index.php' />";
	echo '<p><h4 align=\"center\">Login failed. Please <a href="index.php">Click here</a> to try again.</h4><p>';
}// end of errorMSG() function

	// set_session() function start
function set_session($user, $pass)
{
		$confirm = false;
		$usr = mysql_real_escape_string($user);
		$pwd = mysql_real_escape_string($pass);
		$checklogin = mysql_query("SELECT * FROM user WHERE user_name = '".$usr."' AND user_pwd = '".$pwd."'") or die(mysql_error()); ;
		$result = mysql_num_rows($checklogin);

    if($result == 1)
    {
    	$row = mysql_fetch_array($checklogin);
		$user = new user();
		$user->_set_user($row['user_id'], $row['user_name'], $row['user_pwd'], $row['user_email'], 
						   $row['user_type']);
			
			
			$_SESSION['user'] = serialize($user);
			if(checkSession())
				$confirm = true;
	}
	return $confirm;
}	// end of set_session() function


	// edit_inventory() function start
function edit_inventory($_para)
{
	$selected_item = mysql_query("SELECT * FROM inventory WHERE inv_id = '".$_para."'");
	$edit_item = mysql_num_rows($selected_item);		
	if($edit_item == 1)
	{
		$_row = mysql_fetch_row($selected_item);
		$_inv = new inventory();
		$_inv->_set_inv($_row['0'],$_row['1'],$_row['2'])
?>
	    <form id="edit_inv" name="edit_inv" method="get" action="inventory.php">
        <table border="1" align="center">
    		<tr>
    			<td width="100">Inventory Name</td>
    			<td width="100">Inventory Amt</td>
            </tr>
			<tr>
				<td><input name="invName" type="text" value="<?php echo $_inv->_get_invName(); ?>" /></td>
    			<td><input name="invAmt" type="text" value="<?php echo $_inv->_get_invAmt(); ?>" /></td>
    		</tr>
			<tr>
    			<td><input name="save" type="submit" value="save"/></td>
    			<td></td>
            </tr>
		</table>
    </form>
<?php
	} // end of if(edit_item)
}	// end of edit_inventory() function


function save_item($_id,$_name,$_amt){
			$_id = $_id;
			echo $_id;
			$_name = $_name;
			echo $_name;
			$_amt = $_amt;
			echo $_amt;
			$_update_item = mysql_query("UPDATE inventory SET inv_name = '".$_name."', inv_amt = '".$_amt."' WHERE inv_id = '".$_id."'");
		//echo "<meta http-equiv='refresh' content=0;'inventory.php' />";
}
?>